package zz.app.ustbgsmanager.fragments;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.ArrayList;

import zz.app.ustbgsmanager.R;
import zz.app.ustbgsmanager.adapters.TeachingAssessmentRecyclerViewAdapter;
import zz.app.ustbgsmanager.beans.teachingassessment.CourseAssessment;
import zz.app.ustbgsmanager.other.ShortHorizontalDividerItemDecoration;

/**
 * Created by zz on 2018/6/11 15:50.
 */
public class CourseAssessmentFragment extends Fragment {
    FloatingActionButton fab;
    RecyclerView recyclerView;
    TeachingAssessmentRecyclerViewAdapter adapter;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.layout_assessment_fragment, container, false);
        fab = view.findViewById(R.id.fab);
        adapter = new TeachingAssessmentRecyclerViewAdapter(getContext());
        recyclerView = view.findViewById(R.id.recyclerview);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
        recyclerView.addItemDecoration(new ShortHorizontalDividerItemDecoration(getContext()));
        recyclerView.setAdapter(adapter);
        Bundle bundle = getArguments();
        if (bundle != null) {
            int pos = bundle.getInt("pos");
            if (pos == 0) fab.setVisibility(View.GONE);
        }
        return view;
    }

    public void setData(ArrayList<CourseAssessment> data) {
        if(adapter!=null)
        adapter.setData(data);
    }

    public void clear() {
        adapter.setData(new ArrayList<CourseAssessment>());
    }
}
